from fastapi import APIRouter, Query, Depends
from typing import Optional, List
from api.package_material.report import get_storage_records
from util.JWT import get_current_user

router = APIRouter()

@router.get("/list")
async def get_report_list(
    search: Optional[str] = None,
    storage_type: Optional[str] = None,
    start_date: Optional[str] = None,
    end_date: Optional[str] = None,
    page: int = Query(1, ge=1),
    page_size: int = Query(10, ge=1, le=100),
    id: dict = Depends(get_current_user)
):
    """
    获取存储记录列表，支持多字段搜索
    - search: 搜索关键字（支持编码、单号、类型、描述）
    - storage_type: 存储类型（I: 入库, O: 出库）
    - start_date: 开始日期
    - end_date: 结束日期
    - page: 页码
    - page_size: 每页记录数
    """
    try:
        result = get_storage_records(
            search=search,
            storage_type=storage_type,
            start_date=start_date,
            end_date=end_date,
            page=page,
            page_size=page_size
        )
        return result
    except Exception as e:
        return {
            "code": 500,
            "message": f"获取数据失败: {str(e)}",
            "data": None
        } 